home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / dev / asm / newstartup34.lha / startup_asm34 / Startup.asm < prev    next >
Assembly Source File  |  1995-09-05  |  12KB  |  428 lines

  1. *******************************************************************************
  2. *    "Startup.asm"
  3. *
  4. *    $VER: Startup_asm 3.4 (5.9.95)
  5. *
  6. *    Copyright ⌐ 1995 by Kenneth C. Nilsen/Digital Surface
  7. *    This source is public domain.
  8. *
  9. *    For instructions read the Startup_Asm.doc or see the Startup_example.s
  10. *
  11. *SUMMARY:
  12. *
  13. *StartSkip    =    0 or 1 (0 = wb/cli, 1=cli only (eg. from AsmOne))
  14. *Processor    =    0 or 680x0
  15. *MathProc    =    0 or 6888x/68040
  16. *
  17. *Init:    Version        <"PrgName ver.rev (date)">        (opt)
  18. *    TaskName    <"new task name in qvotes">        (opt)
  19. *    TaskPri        <priority>                (opt)
  20. *    DefLib        <libname wo/.library>,<version>        (opt)
  21. *    DefEnd        ;must end the "Init:" section ALWAYS!    (required!)
  22. *
  23. *Start:    LibBase        <libname wo/.library>            (opt)
  24. *    StartFrom    = 0 (CLI) or <>0 (WB) in D0        (opt)
  25. *    TaskPointer    = pointer to taskstructure  (D0)    (opt)
  26. *    NextArg        = pointer to next argument or 0  (D0)    (opt)
  27. *    Return        <return value> (with RTS)        (recommended)
  28. *
  29. *******************************************************************************
  30.  
  31. zyxMax    = 17    ;max no. of libraries for AllocMem()
  32. zyxBufZ    = 308    ;size of format buffer in bytes for AllocMem()
  33.  
  34. ; (these above settings will require 512 bytes allocated memory (0.5Kb))
  35.  
  36. *-----------------------------------------------------------------------------*
  37. * Macros for Startup.asm
  38. *-----------------------------------------------------------------------------*
  39.  
  40. Return    Macro
  41.     moveq    #\1,d0        ;* if you use rtn code >127, change to "move.l"
  42.     rts                ;exit our program
  43.     EndM
  44.  
  45. DefLib    Macro    ;<Libname wo/ext>,<version>
  46.  
  47.     lea    \1NamX(pc),a1        ;make exclusive library namelabel
  48.     move.l    a1,(a5)+        ;put name into our buffer (if print)
  49.     move.l    a1,zyxNx        ;store name in local label
  50.     moveq    #\2,d0        ;* if you use ver >127, change this to "move.l"
  51.     move.l    d0,(a5)+        ;store version in our buffer
  52.     move.l    d0,zyxVx        ;store version in local label
  53.     jsr    -552(a6)        ;try open library
  54.     move.l    d0,(a5)+        ;store result in our buffer
  55.  
  56.     move.l    d0,\1basX        ;store result in global label
  57.     bne.b    \1zyx            ;if <>0 then ok
  58.  
  59.     bsr.w    zyxLibR            ;print error message
  60.     bra.b    \1zyx            ;go on...
  61.  
  62. \1basX    dc.l    0
  63. \1NamX    dc.b    "\1.library",0        ;library name macro
  64.     even
  65. \1zyx
  66.     EndM
  67.  
  68. DefEnd    Macro
  69.     move.l    #-1,(a5)        ;this terminate our library list
  70.     rts                ;exit init section
  71.     EndM
  72.  
  73. LibBase    Macro    ;<libname wo/ext>
  74.     move.l    \1basX(pc),a6        ;get library base with exclusive name
  75.     EndM
  76.  
  77. TaskName Macro    ;<"name-on-task">
  78.  
  79.     move.l    $4.w,a6            ;exec base
  80.     jsr    -132(a6)        ;Disable()
  81.     move.l    zyxTask(pc),a0        ;get stored task pointer to our task
  82.     move.l    #.TaskN,10(a0)        ;get ptr. to new name and store
  83.     jsr    -138(a6)        ;Enable()
  84.     bra.b    .zyxTsk            ;go on...
  85.  
  86. .TaskN    dc.b    \1            ;task name macro
  87.     dc.b    0            ;null terminate
  88.     even
  89. .zyxTsk
  90.     EndM
  91.  
  92. TaskPri    Macro    ;<pri>
  93.     move.l    $4.w,a6            ;execbase
  94.     move.l    zyxTask(pc),a1        ;get stored task pointer
  95.     moveq    #\1,d0            ;get new task priority
  96.     jsr    -300(a6)        ;SetTaskPri()
  97.     EndM
  98.  
  99. TaskPointer Macro
  100.     move.l    zyxTask(pc),d0        ;give pointer to task in d0
  101.     EndM
  102.  
  103. StartFrom Macro
  104.     move.l    RtnMess(pc),d0        ;if started from WB, d0<>0
  105.     EndM
  106.  
  107. Version    Macro
  108.     bra.w    .zyxVer            ;jump garbage code :)
  109.     dc.b    "$VER: "        ;init header
  110.     dc.b    \1            ;get rest of string from macro
  111.     dc.b    0            ;null terminate
  112.     even
  113. .zyxVer
  114.     EndM
  115.  
  116. NextArg    Macro
  117.     move.l    zyxArgP(pc),d0        ;get address to argument string
  118.     beq.b    *+8            ;none? (from WB) then skip
  119.     move.l    d0,a0            ;use pointer
  120.     bsr.w    zyxGArg            ;go to our internal routine
  121.     move.l    a0,zyxArgP        ;update argument pointer
  122.     tst.l    d0            ;set/unset Z flag
  123.     EndM
  124.  
  125. *-----------------------------------------------------------------------------*
  126. * MAIN routine:
  127. *-----------------------------------------------------------------------------*
  128. GoZYX    move.l    a0,-(sp)        ;store argument pointer
  129.  
  130.     move.l    d0,zyxArgL        ;store length of arg. string
  131.     move.l    a0,zyxArgP        ;store arg. pointer in internal label
  132.  
  133.     move.l    $4.w,a6            ;exec base
  134.  
  135.     move.l    #zyxBufZ,d0        ;set buffer size
  136.     move.l    #$10001,d1        ;requirements (public, clear)
  137.     jsr    -198(a6)        ;AllocMem()
  138.     move.l    d0,zyxBuff        ;store result in label
  139.     beq.w    .DOS            ;Null? then exit
  140.  
  141.     sub.l    a1,a1            ;a1=0 (this task)
  142.     jsr    -294(a6)        ;FindTask()
  143.     move.l    d0,a4            ;copy result
  144.     move.l    d0,zyxTask        ;store for internal use
  145.  
  146.     tst.l    172(a4)            ;where we started from (wb/cli)
  147.     bne.b    .chkPro            ;<>0 then cli
  148.  
  149.     moveq    #StartSkip,d0        ;check if we wanne skip (eg. AsmOne)
  150.     bne.b    .chkPro            ;yepp, then skip
  151.     lea    92(a4),a0        ;get message port address
  152.     jsr    -384(a6)        ;WaitPort()
  153.     lea    92(a4),a0        ;get message port address
  154.     jsr    -372(a6)        ;GetMsg()
  155.     move.l    d0,RtnMess        ;store message pointer in label
  156.  
  157. .chkPro    move.w    296(a6),d5        ;AttnFlags in execbase
  158.     and.l    #$ff,d5            ;we only need the first byte
  159.  
  160.     move.l    #Processor,d7        ;processor we want
  161.     beq.w    .ProOk            ;null? then any will do, skip this part
  162.     cmp.l    #68000,d7        ;or 68000?
  163.     beq.w    .ProOk            ;then skip too...
  164.  
  165. .nxPro1    cmp.l    #68010,d7        ;68010?
  166.     bne.b    .nxPro2            ;no, check next
  167.     and.b    #$cf,d5            ;check bits
  168.     bne.w    .ProOk            ;we got a 68010 or higher
  169.     bra.w    .ProErr            ;we got lower, we can't start...
  170.  
  171. .nxPro2    cmp.l    #68020,d7        ;same as above, just higher processor
  172.     bne.b    .nxPro3
  173.     and.b    #$ce,d5
  174.     bne.w    .ProOk
  175.     bra.b    .ProErr
  176.  
  177. .nxPro3    cmp.l    #68030,d7
  178.     bne.b    .nxPro4
  179.     and.b    #$cc,d5
  180.     bne.b    .ProOk
  181.     bra.b    .ProErr
  182.  
  183. .nxPro4    cmp.l    #68040,d7
  184.     bne.b    .nxPro5
  185.     and.b    #$c8,d5
  186.     bne.b    .ProOk
  187.     bra.b    .ProErr
  188.  
  189. .nxPro5    cmp.l    #68060,d7        ;we want a 68060 (yes, we do :) )
  190.     bne.b    .ProWho            ;not? then I dont know about any higher
  191.     btst    #7,d5            ;test if it is a 68060 we're using
  192.     beq.b    .ProErr            ;nope
  193.     btst    #6,d5            ;are you sure?
  194.     bne.b    .ProOk            ;yepp, continue
  195.     bra.b    .ProErr            ;not a 060, print error message
  196.  
  197. .ProWho    lea    ProcWho(pc),a0        ;unknown processor required, print
  198.     move.l    #Processor,ProcNum    ;message about it.
  199.     bra.b    .format
  200.  
  201. .ProErr    lea    ProcErr(pc),a0        ;we don't got the processor required
  202.     move.l    #Processor,ProcNum    ;print message about it...
  203.  
  204. .format    lea    ProcNum(pc),a1
  205.     bsr.w    zyxPrt            ;jump to our cli print routine
  206.     bra.w    .End
  207.  
  208. .ProOk    move.l    #MathProc,d7        ;time to check for math-co-processor
  209.     beq.w    .MathOk            ;null? then any will do...
  210.  
  211.     cmp.l    #68881,d7        ;a 68881?
  212.     bne.b    .Math2            ;no check next
  213.     and.b    #$70,d5            ;check flags
  214.     bne.b    .MathOk            ;we got it
  215.     bra.b    .MathEr            ;sorry...
  216.  
  217. .Math2    cmp.l    #68882,d7        ;sae as above
  218.     bne.b    .Math3
  219.     and.b    #$60,d5
  220.     bne.b    .MathOk
  221.     bra.b    .MathEr
  222.  
  223. .Math3    cmp.l    #68040,d7        ;we have a 68040 with FPU not 881/882
  224.     bne.b    .MathEr            ;unknown FPU if any else...
  225.     btst    #6,d5            ;we got it?
  226.     bne.b    .MathOk            ;yepp, continue
  227.  
  228. .MathEr    lea    MathErr(pc),a0        ;print error message...
  229.     move.l    #MathProc,ProcNum
  230.     bra.w    .format
  231.  
  232. .MathOk    bsr.w    zyxLibO            ;oki, open our libraries
  233.  
  234.     tst.w    zyxLR            ;any error?
  235.     bne.b    .noShow            ;yepp, don't jump to main program
  236.  
  237.     move.l    zyxArgP(pc),a0        ;get arg. pointer
  238.     move.l    zyxArgL(pc),d0        ;get arg. length
  239.  
  240.     bsr.w    Start            ;start main program
  241.     move.l    d0,zyxVal        ;store return code
  242.  
  243. .noShow    bsr.w    zyxLibC            ;close libraries if any
  244.  
  245. .End    move.l    zyxBuff(pc),d0        ;get pointer to our buffer
  246.     beq.b    .noBuff            ;no buffer?!?
  247.     move.l    d0,a1            ;copy pointer
  248.     move.l    #zyxBufZ,d0        ;length of buffer
  249.     jsr    -210(a6)        ;FreeMem()
  250.  
  251. .noBuff    tst.l    RtnMess            ;from WB?
  252.     beq.w    .DOS            ;nope, from CLI
  253.  
  254.     jsr    -132(a6)        ;Disable()
  255.     move.l    RtnMess(pc),a1        ;put message in a1
  256.     jsr    -138(a6)        ;Enable()
  257.  
  258. .DOS    movem.l    (sp)+,a0        ;restore stack, put arg. pointer back
  259.     move.l    zyxVal(pc),d0        ;set return code
  260.     rts                ;BYE! :)
  261.  
  262. zyxDo    move.b    d0,(a3)+        ;for RawDoFmt(), process routine
  263.     rts
  264.  
  265. zyxPrt    movem.l    d0-a6,-(sp)        ;store regs. on stack
  266.  
  267.     lea    zyxDo(pc),a2        ;process
  268.     move.l    zyxBuff(pc),a3        ;format buffer
  269.     jsr    -522(a6)        ;RawDoFmt()
  270.  
  271.     moveq    #0,d0            ;any version
  272.     lea    zyxDos(pc),a1        ;ptr. to dos.library name
  273.     jsr    -552(a6)        ;OpenLibrary()
  274.     tst.l    d0            ;failed?
  275.     beq.b    .exit            ;jepp, exit
  276.     move.l    d0,a6            ;use dosbase
  277.  
  278.     jsr    -60(a6)            ;Output()
  279.     move.l    d0,d1            ;copy, set Z, failed?
  280.     beq.b    .clDos            ;no output -> close dos.library
  281.  
  282.     move.l    zyxBuff(pc),a0        ;get ptr. to our buffer
  283.     move.l    a0,d2            ;copy pointer
  284.     moveq    #0,d3            ;clear D3 (length of buffer)
  285. .count    move.b    (a0)+,d0        ;get one char
  286.     beq.b    .cntEnd            ;null? yepp, found end...
  287.     addq    #1,d3            ;nope, add one in length
  288.     bra.b    .count            ;continue
  289.  
  290. .cntEnd    jsr    -48(a6)            ;print buffer to output handler (CLI)
  291.  
  292. .clDos    move.l    a6,a1            ;copy dosbase to a1
  293.     move.l    $4.w,a6            ;get exebase
  294.     jsr    -414(a6)        ;CloseLibrary()
  295.  
  296. .exit    movem.l    (sp)+,d0-a6        ;restore stack
  297.     rts                ;return
  298.  
  299. zyxLibO    move.l    #4*3*zyxMax,d0        ;library buffer size 12*zyxMax (192)
  300.     move.l    #$10001,d1        ;any mem, clear it
  301.     jsr    -198(a6)        ;AllocMem()
  302.     move.l    d0,zyxMem        ;store result
  303.     beq.b    .memErr            ;null? then error
  304.  
  305.     move.l    d0,a5            ;use buffer
  306.     bsr.w    Init            ;jump to init section (see macros)
  307.  
  308.     rts                ;done
  309.  
  310. .memErr    lea    zyxFR(pc),a0        ;get format text
  311.     lea    zyxMeR(pc),a1        ;get input string
  312.  
  313.     bsr.w    zyxPrt            ;print message about low memory
  314.  
  315.     move.w    #-1,zyxLR        ;failed, don't start main program
  316.     rts                ;return
  317.  
  318. zyxLibC    move.l    $4.w,a6            ;execbase
  319.  
  320.     move.l    zyxMem(pc),d0        ;library buffer
  321.     beq.w    .noLibs            ;null? then no libraries
  322.     move.l    d0,a5            ;use pointer
  323.  
  324. .loop    cmp.l    #-1,(a5)        ;end?
  325.     beq.b    .clEnd            ;yepp, then done!
  326.     move.l    8(a5),d0        ;get library base
  327.     beq.b    .noCl            ;null? then this lib. failed to open
  328.     move.l    d0,a1            ;use base
  329.     jsr    -414(a6)        ;CloseLibrary()
  330. .noCl    lea    12(a5),a5        ;get next library base
  331.     bra.b    .loop            ;continue
  332.  
  333. .clEnd    move.l    zyxMem(pc),a1        ;get lib. buffer pointer
  334.     move.l    #4*3*zyxMax,d0        ;size
  335.     jsr    -210(a6)        ;FreeMem()
  336.  
  337. .noLibs    rts                ;return
  338.  
  339. zyxLibR    move.w    #-1,zyxLR        ;if any errors, set error flag
  340.  
  341.     lea    zyxLib(pc),a0
  342.     lea    zyxNx(pc),a1
  343.     bsr.w    zyxPrt            ;print library name
  344.  
  345.     lea    zyxVer(pc),a0
  346.     lea    zyxVx(pc),a1
  347.     bsr.w    zyxPrt            ;print library version
  348.  
  349.     rts                ;return
  350.  
  351. zyxGArg    move.b    (a0)+,d0        ;get a char from arg. line
  352.     beq.w    .end            ;null? end of line
  353.     cmp.b    #10,d0            ;linefeed?
  354.     beq.w    .end            ;end of line
  355.     cmp.b    #9,d0            ;tab?
  356.     beq.b    zyxGArg            ;get another char
  357.     cmp.b    #32,d0            ;space?
  358.     beq.b    zyxGArg            ;get another char
  359.  
  360.     move.l    zyxBuff(pc),a1        ;our text buffer
  361.     lea    -1(a0),a0        ;go back one byte on arg. line
  362. .copy    move.b    (a0)+,d0        ;copy char to d0
  363.     beq.b    .stop            ;null? then stop copy
  364.     cmp.b    #10,d0            ;linefeed?
  365.     beq.b    .stop            ;stop copy
  366.     cmp.b    #32,d0            ;space?
  367.     beq.b    .eol            ;then this arg. is done
  368. .cont    cmp.b    #'*',d0            ;asterix?
  369.     beq.b    .chkSpc            ;check for special functions
  370.     cmp.b    #'"',d0            ;qvote?
  371.     beq.b    .toggle            ;toggle copy mode
  372. .noChk    move.b    d0,(a1)+        ;copy passed char to our buffer
  373. .cont2    bra.b    .copy            ;continue copy
  374.  
  375. .chkSpc    cmp.b    #'"',(a0)        ;a qvote want to be used?
  376.     bne.b    .chk2            ;no, check for a linefeed then...
  377.     move.b    #'"',(a1)+        ;copy a qvote to our buffer
  378.     lea    1(a0),a0        ;skip one byte (2(*")->1("))
  379.     bra.b    .copy            ;continue copy argument
  380. .chk2    cmp.b    #'n',(a0)        ;a linefeed?
  381.     bne.b    .noChk            ;nope, skip special funcs.
  382.     move.b    #10,(a1)+        ;copy a linefeed to our buffer
  383.     lea    1(a0),a0        ;make 2 -> 1
  384.     bra.b    .copy            ;continue copy
  385.  
  386. .toggle    tst.w    zyxQ            ;already toggled?
  387.     beq.b    .set            ;nope, then toggle
  388.     clr.w    zyxQ            ;re toggle
  389.     bra.b    .stop            ;end of argument
  390. .set    move.w    #-1,zyxQ        ;toggle so we can use space in arg.
  391.     bra.b    .cont2            ;continue copying argument
  392.  
  393. .eol    tst.w    zyxQ            ;end of line -> toggled?
  394.     bne.b    .cont            ;jepp, continue
  395.  
  396. .stop    tst.w    zyxQ            ;toggled?
  397.     bne.b    .end            ;jepp,don't care about this arg (error)
  398.     clr.b    (a1)            ;terminate buffer
  399.     move.l    zyxBuff(pc),d0        ;pointer to extracted argument
  400.     rts                ;return to macro
  401.  
  402. .end    moveq    #0,d0            ;no more args
  403.     rts                ;return to macro
  404.  
  405. RtnMess    dc.l    0            ;pointer to WB message
  406. ProcNum    dc.l    0            ;prossecor wanted
  407. zyxArgL    dc.l    0            ;argument line length
  408. zyxArgP    dc.l    0            ;pointer to argument string
  409. zyxVal    dc.l    0            ;return code
  410. zyxMem    dc.l    0            ;pointer to library buffer
  411. zyxNx    dc.l    0            ;temp lib. name
  412. zyxVx    dc.l    0            ;temp lib. version
  413. zyxTask    dc.l    0            ;pointer to task structure
  414. zyxLR    dc.w    0            ;error flag
  415. zyxQ    dc.w    0            ;toggle flag for qvotes
  416. zyxBuff    dc.l    0            ;pointer to string buffer
  417. zyxMeR    dc.l    zyxMemR            ;pointer to a format string
  418.  
  419. zyxDos    dc.b    'dos.library',0
  420. zyxLib    dc.b    "Couldn't open %s ",0
  421. zyxVer    dc.b    'version %ld.',10,0
  422. zyxMemR    dc.b    'Not enough memory!',10,0
  423. zyxFR    dc.b    '%s',0
  424. ProcWho    dc.b    'INTERN: %ld ?',10,0
  425. ProcErr    dc.b    'This program require %ld+',10,0
  426. MathErr    dc.b    'This program need %ld FPU',10,0
  427.     even
  428.